﻿using System;
using System.Collections.Generic;
using System.Text;
using NumberChangedEventHandler = AsyncCallback.AsyncEvent.GernericEventHandler<int>;
using System.Diagnostics;

namespace AsyncCallback.AsyncEvent
{
    class MyPublisher
    {
        public event NumberChangedEventHandler NumberChanged;
        public void FireEvent(int number)
        {
            if (NumberChanged != null)
            {
                NumberChanged(number);
            }
        }

        public void AsyncFireEvent(int number)
        {
            //if (NumberChanged == null)
            //{
            //    return;
            //}
            EventsHelper.FireAsync(NumberChanged, number);
            EventsHelper2.FireAsync<int>(NumberChanged, number);
            //Delegate[] delegate_list = NumberChanged.GetInvocationList();
            //foreach (Delegate del in delegate_list)
            //{
            //    NumberChangedEventHandler handler = del as NumberChangedEventHandler;
            //    if (handler != null)
            //    {
            //        handler.BeginInvoke(number, null, null);
            //    }
            //}
        }
    }

    class MySubscriber
    {
        public void OnNumberChanged(int number)
        {
            Trace.WriteLine("最新数字:" + number);
        }
    }
}
